home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
L' Effet Pommier 3
/
L'Effet Pommier - Volume 03.iso
/
Programmation
/
Gooey1.3.1
/
C Templates
/
mmCommon.c
< prev
next >
Wrap
Text File
|
1995-01-31
|
69KB
|
2,093 lines
$$Message MM Common, mm:mmCommon$Prototype.name$.c
$$File mm:mmCommon$Prototype.name$.c
/* $CopyRight$ */
/* mmCommon$Prototype.name$ Common */
/*
Name: mmCommon$Prototype.name$.c
Function: Common for the Marksman¬ specific code.
History: $Date$ Original by $Author$
*/
#include "mmCommon$Prototype.name$.h" /* Common */
/* ======================================================= */
UserEventHRec UserEventList; /* User Event record list start */
EventRecord myEvent; /* Event record for all events */
Boolean WNE; /* WaitNextEvent trap is available */
short SleepValue; /* Sleep value for Wait on events */
Boolean doneFlag; /* Exit program flag */
TEHandle theInput; /* Used in text edit selections */
RgnHandle cursorRgn; /* Cursor region for WaitNextEvent */
short ReplyMode; /* Reply mode for AppleEvents */
Rect tempRect; /* Temporary rect, not for long term use */
Str255 sTemp; /* Temporary string, not for long term use */
short tempChar; /* Temporary use character */
long LTemp; /* Temporary use long variable */
short DType; /* Temporary use Type of dialog item */
Handle DItem; /* Temporary use Handle to the dialog item */
ControlHandle CItem; /* Temporary use Control handle */
WindowLocRec theWindowLocRec;
Boolean Doing_MovableModal; /* For Movable Modal dialogs */
Boolean HoldOffUserEvents; /* Flag for holding off UserEvents */
Boolean InTheForeground; /* Flag for running in MultiFinder foreground */
HasRec Has; /* Gestalt check results */
FileRec Files; /* Reading and writing files */
PrintingRec Printing; /* Printing */
RGBColor Black_ForeColor,White_BackColor;/* Standard colors */
ProcessSerialNumber gSelfPSN;
AEAddressDesc gSelfAddress;
$$Loop Menus
MenuHandle Menu_$Menu.name$; /* Menu handle, $Menu.FullName$ */
$$EndLoop
$$Loop HierMenus
MenuHandle Menu_$Menu.name$; /* Hier Menu handle, $Menu.FullName$ */
$$EndLoop
$$Loop Alerts
$Worksheet.name$Rec Rec_$Worksheet.name$; /* Record for Alert, "$Worksheet.FullName$" */
$$EndLoop Alerts
$$Loop Dialogs
$Worksheet.name$Rec Rec_$Worksheet.name$; /* Record for dialog, "$Worksheet.FullName$" */
$$EndLoop
$$Loop Windows
$Worksheet.name$RecPtr RecPtr_$Worksheet.name$; /* Record pointer for window, "$Worksheet.FullName$" */
$Worksheet.name$RecPtr ListRecPtr_$Worksheet.name$;
Boolean MultipleAllowed_$Worksheet.name$;
$$EndLoop
#define LowestWindowIndex 0
#define HighestWindowIndex 10
WindowPtr TopMostWindows[12];
WindowPtr BottomMostWindows[12];
#define lmWindowList 0x000009D6
/* Variables used by Select Volume */
short Last_vRefNum;
long Last_parID;
Str255 Last_Name;
#pragma segment Main
static void VerifyWindowLayers(void);
static pascal Boolean mySelectCustomFileFilter(CInfoPBPtr pb,Ptr myDataPtr);
static pascal short mySelectDlgFilter(short item,DialogPtr theDialog,Ptr myDataPtr);
static void BasicSetup(DialogPtr theDialog,short theItem,Boolean Enabled,short MessageResID,
ControlHandle *theCItem);
/* ======================================================= */
/* ======================================================= */
void InitAppleEvents(void) /* Initialize for AppleEvents */
{
OSErr err; /* Error */
AEEventHandlerUPP theRoutine;
theRoutine = NewAEEventHandlerProc(DispatchAppleEvent);
err = AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,
theRoutine,kAEOpenApplication,false);
err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,
theRoutine,kAEOpenDocuments,false);
err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,
theRoutine,kAEPrintDocuments,false);
err = AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,
theRoutine,kAEQuitApplication,false);
//err = AEObjectInit(); /* Init the AE Object code */
gSelfPSN.highLongOfPSN = 0; /* Init to the current process ID */
gSelfPSN.lowLongOfPSN = kCurrentProcess;
err = AECreateDesc(typeProcessSerialNumber,(Ptr)&gSelfPSN,sizeof(ProcessSerialNumber),&gSelfAddress);
}
/* ======================================================= */
/* Routine: VerifyWindowLayers */
/* Purpose: Verify all windows are at the proper layer */
static void VerifyWindowLayers(void)
{
short Index,theLayer;
WindowPeek theWindowPeek;
long *theWindowListPtr,theRefCon;
WindowPtr theWindowPtr,theOutOfOrderWindowPtr;
Boolean Out_Of_Place;
Out_Of_Place = true;
while (Out_Of_Place)
{
Mk_ClearLayers(); /* Clear all arrays, we will refill them */
theOutOfOrderWindowPtr = nil;
Out_Of_Place = false;
Index = HighestWindowIndex + 1;
theWindowListPtr = (long *)lmWindowList; /* Get the window list start */
theWindowPeek = (WindowPeek)*theWindowListPtr; /* Get the window list start */
while ((theWindowPeek != nil) && (!Out_Of_Place))
{
if ((theWindowPeek->visible) && (theWindowPeek->windowKind == userKind))
{
theWindowPtr = (WindowPtr)theWindowPeek;/* Get the window pointer */
theRefCon = GetWRefCon(theWindowPtr);
theRefCon = theRefCon & 0xFF000000; /* Mask off, to get the layer */
theLayer = theRefCon >> 24; /* Move into lower byte */
if (theLayer < LowestWindowIndex) /* Pin at 0 */
theLayer = LowestWindowIndex;
if (theLayer > HighestWindowIndex) /* Pin at top */
theLayer = HighestWindowIndex;
if (theLayer > Index)
{
Index = theLayer;
Out_Of_Place = true;
if (theOutOfOrderWindowPtr != nil)
SendBehind(theOutOfOrderWindowPtr,theWindowPtr);
}
else if (theLayer < Index)
{
Index = theLayer;
TopMostWindows[theLayer] = theWindowPtr;
BottomMostWindows[theLayer] = theWindowPtr;
}
else
BottomMostWindows[theLayer] = theWindowPtr;
theOutOfOrderWindowPtr = theWindowPtr;
}
theWindowPeek = theWindowPeek->nextWindow;/* Get the next window */
}
}
}
/* ======================================================= */
/* Routine: Mk_BehindWindow */
/* Purpose: Get which window to place us behind */
WindowPtr Mk_BehindWindow(short theLayer)
{
short LayerIndex;
WindowPtr ReturnWindowPtr;
ReturnWindowPtr = (WindowPtr)-1; /* Default to In front of everyone */
VerifyWindowLayers(); /* Make sure our tables are up to date */
LayerIndex = HighestWindowIndex;
while ((LayerIndex > theLayer) && (LayerIndex >= LowestWindowIndex))
{
if (BottomMostWindows[LayerIndex] != nil)
ReturnWindowPtr = BottomMostWindows[LayerIndex];
LayerIndex = LayerIndex - 1;
}
return(ReturnWindowPtr);
}
/* ======================================================= */
/* Routine: Mk_RegisterWindow */
/* Purpose: Place layer in RefCon and verify layers */
void Mk_RegisterWindow(WindowPtr theWindowPtr,short theLayer)
{
long theRefCon;
long theLLayer;
theRefCon = GetWRefCon(theWindowPtr); /* Get the window refcon */
theRefCon = theRefCon & 0x00FFFFFF; /* Mask off, in case something else is there */
theLLayer = theLayer; /* Get the window layer */
theLLayer = theLLayer << 24; /* Move into upper byte */
theRefCon = theRefCon | theLLayer; /* Mask layer into refcon */
SetWRefCon(theWindowPtr, theRefCon); /* Set the new refcon */
VerifyWindowLayers(); /* Make sure our tables are up to date */
}
/* ======================================================= */
/* Routine: Mk_ClearLayers */
/* Purpose: Init our arrays for layered windows */
void Mk_ClearLayers(void)
{
short Index;
for (Index = LowestWindowIndex; Index <= HighestWindowIndex; Index++)
{
TopMostWindows[Index] = nil;
BottomMostWindows[Index] = nil;
}
}
/* ======================================================= */
/* Routine: Mk_HiliteWindow */
/* Purpose: Hilite our layered window */
void Mk_HiliteWindow(WindowPtr theWindowPtr)
{
WindowPeek theWindowPeek;
long *theWindowListPtr;
WindowPtr WasHilighted,CkHilighted,BehindWindow;
long theRefCon;
short theLayer,theWasLayer;
VerifyWindowLayers(); /* Make sure our tables are up to date */
theRefCon = GetWRefCon(theWindowPtr);
theRefCon = 0xFF000000 & theRefCon; /* Mask for top byte */
theLayer = theRefCon >> 24; /* Move into lower byte */
if (theLayer < LowestWindowIndex) /* Pin at 0 */
theLayer = LowestWindowIndex;
if (theLayer > HighestWindowIndex) /* Pin at top */
theLayer = HighestWindowIndex;
theWindowListPtr = (long *)lmWindowList; /* Get the window list start */
theWindowPeek = (WindowPeek)*theWindowListPtr; /* Get the window list start */
WasHilighted = nil;
while (theWindowPeek != nil)
{
if ((theWindowPeek->visible) && (theWindowPeek->windowKind == userKind))
{
if (theWindowPeek->hilited)
{
CkHilighted = (WindowPtr)theWindowPeek;
theRefCon = GetWRefCon(CkHilighted);
theRefCon = 0xFF000000 & theRefCon; /* Mask for top byte */
theWasLayer = theRefCon >> 24; /* Move into lower byte */
if (theWasLayer == theLayer)
WasHilighted = CkHilighted;
}
}
theWindowPeek = theWindowPeek->nextWindow;
}
if (theWindowPtr != WasHilighted)
{
if (WasHilighted != nil)
{
theRefCon = GetWRefCon(WasHilighted);
theRefCon = 0xFF000000 & theRefCon; /* Mask for top byte */
theWasLayer = theRefCon >> 24; /* Move into lower byte */
if (theWasLayer < LowestWindowIndex) /* Pin at 0 */
theWasLayer = LowestWindowIndex;
if (theWasLayer > HighestWindowIndex) /* Pin at top */
theWasLayer = HighestWindowIndex;
if (theWasLayer == theLayer)
{
HiliteWindow(WasHilighted, false);
myEvent.message = (long)WasHilighted;
myEvent.modifiers = 0;
DoActivate(); /* Deactivate, do links */
}
}
HiliteWindow(theWindowPtr, true);
myEvent.message = (long)theWindowPtr;
myEvent.modifiers = 1;
DoActivate(); /* Activate, do links */
BehindWindow = Mk_BehindWindow(theLayer); /* Move to correct layer on the screen */
if ((long)BehindWindow == -1L)
BringToFront(theWindowPtr);
else
SendBehind(theWindowPtr, BehindWindow);
TopMostWindows[theLayer] = theWindowPtr;
}
}
/* ======================================================= */
/* Routine: Mk_DragWindow */
/* Purpose: Drag our layered window */
void Mk_DragWindow(WindowPtr theWindowPtr,Point where, Rect bounds)
{
GrafPtr savePort;
CGrafPtr WMgrPort;
RgnHandle hRegion,dragRgn;
WindowPeek theWindowPeek;
long result;
short Horz,Vert;
CWindowPtr theCWindowPtr;
Rect portBounds;
PixMapHandle thePixMapHandle;
if (WaitMouseUp())
{
theWindowPeek = (WindowPeek)theWindowPtr;
theCWindowPtr = (CWindowPtr)theWindowPtr;
GetPort(&savePort);
if (Has.ColorQD)
GetCWMgrPort(&WMgrPort);
else
GetWMgrPort((GrafPtr *)&WMgrPort);
SetPort((GrafPtr)WMgrPort);
hRegion = GetGrayRgn();
SetClip(hRegion);
#if defined(THINK_C) || defined(THINK_CPLUS) || defined(__SC__)
ClipAbove(theWindowPeek);
#else
ClipAbove((WindowRef)theWindowPeek);
#endif
dragRgn = NewRgn();
CopyRgn(theWindowPeek->strucRgn, dragRgn);
result = DragGrayRgn(dragRgn, where, &bounds, &bounds, 0, nil);
Horz = (result & 0x0000FFFF);
Vert = (result >> 16) & 0x0000FFFF;
if ((Vert != 0x8000) && (Horz != 0x8000))
{
if ((theCWindowPtr->portVersion & 0xC000) != 0)
{
thePixMapHandle = theCWindowPtr->portPixMap;
portBounds = (*thePixMapHandle)->bounds;
}
else
portBounds = theWindowPtr->portBits.bounds;
Horz = Horz + (theWindowPtr->portRect.left - portBounds.left);
Vert = Vert + (theWindowPtr->portRect.top - portBounds.top);
MoveWindow(theWindowPtr, Horz, Vert, false);
}
DisposeRgn(dragRgn);
SetPort(savePort);
}
}
/* ======================================================= */
/* Routine: Mk_Is_FrontWindow */
/* Purpose: Get the front window */
Boolean Mk_Is_FrontWindow(WindowPtr theWindowPtr)
{
Boolean IsFront;
short Index;
IsFront = false;
for (Index = LowestWindowIndex; Index <= HighestWindowIndex; Index++)
{
if (TopMostWindows[Index] == theWindowPtr)
IsFront = true;
}
return(IsFront);
}
/* ======================================================= */
/* Routine: Mk_CloseLayeredWindow */
/* Purpose: Close a layered window */
void Mk_CloseLayeredWindow(WindowPtr theWindowPtr)
{
short Index;
for (Index = LowestWindowIndex; Index <= HighestWindowIndex; Index++)
{
if (TopMostWindows[Index] == theWindowPtr)
TopMostWindows[Index] = nil;
if (BottomMostWindows[Index] == theWindowPtr)
BottomMostWindows[Index] = nil;
}
VerifyWindowLayers(); /* Make sure our tables are up to date */
}
/* ======================================================= */
/* Routine: GetPreferences */
/* Purpose: Get the preferences */
void GetPreferences(void)
{
short foundVRefNum,PrefsRefNum,FormatRevision,thePrefsFormatRevision;
long result,foundDirID,DataSize,count,PrefsRecSize;
OSErr theError;
Boolean GotPreferences,HasFindFolder;
Str255 thePrefsFilename;
Handle PrefsHandle;
FSSpec PrefsFSSpec;
OSType PrefCreator,PrefType;
SysEnvRec theEnv;
/* Get parameters to use */
U_GetPrefParams(&PrefCreator,&PrefType,&thePrefsFilename,&PrefsRecSize,&thePrefsFormatRevision);
GotPreferences = false; /* No prefs yet */
HasFindFolder = false; /* No FindFolder routine avail yet */
PrefsRefNum = 0; /* No prefs file yet */
if (Has.Gestalt) /* Must have Gestalt */
{
theError = Gestalt(gestaltFindFolderAttr,&result);/* Need FindFolder */
if ((theError == 0) && ((result & (0x00000001 << gestaltFindFolderPresent)) != 0))
HasFindFolder = true;
if (HasFindFolder) /* Must have FindFolder */
{
theError = FindFolder(kOnSystemDisk,kPreferencesFolderType,kCreateFolder,&foundVRefNum,&foundDirID);/* Get preference folder */
if (theError == 0)
{
theError = FSMakeFSSpec(foundVRefNum,foundDirID,thePrefsFilename,&PrefsFSSpec);
if (theError == fnfErr) /* File not found */
theError = FSpCreate(&PrefsFSSpec,PrefCreator,PrefType,0);/* Create the file */
theError = FSpOpenDF(&PrefsFSSpec,fsRdWrPerm,&PrefsRefNum);/* Open the file */
}
}
else
{
theError = SysEnvirons(1,&theEnv); /* Get volume environs */
theError = FSOpen(thePrefsFilename,theEnv.sysVRefNum,&PrefsRefNum);/* Open the file */
if (theError == fnfErr) /* File not found */
{
theError = Create(thePrefsFilename,theEnv.sysVRefNum,PrefCreator,PrefType);/* Create the file */
theError = FSOpen(thePrefsFilename,theEnv.sysVRefNum,&PrefsRefNum);/* Open the file */
}
}
if (theError == 0)
{
theError = GetEOF(PrefsRefNum,&DataSize); /* See if data in the file */
if (DataSize > 0) /* Must have data in the file to go on */
{
count = 2; /* Revision number size */
theError = FSRead(PrefsRefNum,&count,&FormatRevision);/* Get revision number */
theError = SetFPos(PrefsRefNum,fsFromStart,0);/* Beginning again */
if ((FormatRevision == thePrefsFormatRevision) && (PrefsRecSize > 0))/* Only do if up to date revision */
{
PrefsHandle = NewHandleClear(PrefsRecSize);/* Get space for the prefs */
if (PrefsHandle != nil) /* Make sure we got our little tiny handle */
{
HLock(PrefsHandle); /* Lock this for safety */
count = PrefsRecSize; /* See how much data to read */
theError = FSRead(PrefsRefNum,&count,*PrefsHandle);/* Read it on in */
if (theError == 0)
U_GetPreferences(PrefsHandle);/* Let the user get the prefs */
GotPreferences = true; /* Got our preferences */
HUnlock(PrefsHandle); /* OK to unlock now */
DisposeHandle(PrefsHandle); /* All done with this record */
}
}
else
U_ReadPrefsPrivate(PrefsRefNum); /* Let the user read the prefs himself */
}
if (PrefsRefNum != 0) /* Done with the file , close it */
theError = FSClose(PrefsRefNum);
}
}
if (!GotPreferences ) /* If we did not get prefs , use default values */
SetPreferences(); /* Set the default values */
}
/* ======================================================= */
/* Routine: SetPreferences */
/* Purpose: Set new preferences */
void SetPreferences(void)
{
Str255 thePrefsFilename;
OSErr theError;
long result,foundDirID,count,PrefsRecSize;
short foundVRefNum,PrefsRefNum,thePrefsFormatRevision;
Handle PrefsHandle;
Boolean HasFindFolder;
FSSpec PrefsFSSpec;
OSType PrefCreator,PrefType;
SysEnvRec theEnv;
/* Get parameters to use */
U_GetPrefParams(&PrefCreator,&PrefType,&thePrefsFilename,&PrefsRecSize,&thePrefsFormatRevision);
PrefsRefNum = 0;
PrefsHandle = NewHandleClear(PrefsRecSize); /* Allocate the prefs space holder */
if (PrefsHandle != nil)
{
HLock(PrefsHandle); /* Lock for safety */
U_SetPreferences(PrefsHandle); /* Let the user set the other pref values */
HasFindFolder = false;
if (Has.Gestalt) /* Must have Gestalt */
{
theError = Gestalt(gestaltFindFolderAttr,&result);/* Need FindFolder */
if ((theError == 0) && ((result & (0x00000001 << gestaltFindFolderPresent)) != 0))/* See if FindFolder */
HasFindFolder = true;
if (HasFindFolder ) /* Must have FindFolder */
{
theError = FindFolder(kOnSystemDisk,kPreferencesFolderType,kCreateFolder,&foundVRefNum,&foundDirID);
if (theError == 0)
{
theError = FSMakeFSSpec(foundVRefNum,foundDirID,thePrefsFilename,&PrefsFSSpec);
if (theError == fnfErr) /* File not found */
theError = FSpCreate(&PrefsFSSpec,PrefCreator,PrefType,0);/* Create the file */
theError = FSpOpenDF(&PrefsFSSpec,fsRdWrPerm,&PrefsRefNum);/* Open the file */
}
}
else
{
theError = SysEnvirons(1,&theEnv); /* Get volume environs */
theError = FSOpen(thePrefsFilename,theEnv.sysVRefNum,&PrefsRefNum);/* Open the file */
if (theError == fnfErr) /* File not found */
{
theError = Create(thePrefsFilename,theEnv.sysVRefNum,PrefCreator,PrefType);/* Create the file */
theError = FSOpen(thePrefsFilename,theEnv.sysVRefNum,&PrefsRefNum);/* Open the file */
}
}
if (theError == 0)
{
count = PrefsRecSize;
theError = FSWrite(PrefsRefNum,&count,*PrefsHandle);/* Write new prefs */
theError = SetEOF(PrefsRefNum,count); /* Reset EOF */
if (PrefsRefNum != 0)
theError = FSClose(PrefsRefNum); /* Close file */
HUnlock(PrefsHandle);
DisposeHandle(PrefsHandle); /* Done with Prefs handle */
}
}
}
}
/* ======================================================= */
void PositionWindow(WindowPtr theWindow,Point WantLocation,Point DefaultPosition)
{
Boolean FitsOK;
Rect WindowRect;
GrafPtr theDesktopPort;
RgnHandle theRgn,the2Rgn;
FitsOK = false; /*Init to not on current screen(s) */
WindowRect = theWindow->portRect; /* Save the rect to get the size */
OffsetRect(&WindowRect,-WindowRect.left,-WindowRect.top); /* Offset to 0,0 */
OffsetRect(&WindowRect,WantLocation.h,WantLocation.v); /* Offset to wanted location */
GetWMgrPort(&theDesktopPort); /* Get the screen */
theRgn = NewRgn(); /* Make temp regions */
the2Rgn = NewRgn();
RectRgn(theRgn,&WindowRect); /* First region to our window rectangle on the screen */
SectRgn(theRgn,theDesktopPort->visRgn,the2Rgn); /* Do the intersection with the screen and window */
if (EqualRgn(theRgn,the2Rgn)) /* If all of window in the screen area then ... */
FitsOK = true; /* ...all of the window is on the screen area */
if (EmptyRgn(the2Rgn))
FitsOK = false;
DisposeRgn(theRgn); /* Dispose of temp regions */
DisposeRgn(the2Rgn);
if ((FitsOK) && ((WantLocation.h != 0) || (WantLocation.v != 0))) /* If all of window in the screen area then ... */
MoveWindow(theWindow,WantLocation.h,WantLocation.v,false); /* Move to saved location */
else
MoveWindow(theWindow,DefaultPosition.h,DefaultPosition.v,false); /* Move to original location */
}
/* ======================================================= */
/* Routine: PStrCopy */
/* Purpose: Copy Pascal strings */
void PStrCopy(Str255 *SourceString, Str255 *DestString)/* Copy Pascal strings */
{
*DestString[0] = *SourceString[0]; /* Get the string size */
if (*DestString[0] != 0) /* Do if there is anything in the string */
BlockMove(SourceString,DestString,*DestString[0]+1);
}
/* ======================================================= */
/* Routine: PStrCat */
/* Purpose: Concat Pascal strings */
void PStrCat(Str255 *SourceString, Str255 *DestString)/* Concat Pascal strings */
{
short OldDestLength,NewDestLength,SizeFromSource;
OldDestLength = *DestString[0]; /* Get the string old length */
SizeFromSource = *SourceString[0]; /* Get the source length */
NewDestLength = OldDestLength + SizeFromSource; /* Get the string new length */
if (NewDestLength > 255) /* Compare to length of the final string */
{
NewDestLength = 255; /* The string final length */
SizeFromSource = 255 - OldDestLength; /* The string final length */
}
*DestString[0] = NewDestLength; /* Set the string length */
if (SizeFromSource > 0) /* Do if there is anything in the string */
BlockMove((Ptr)((long)SourceString + 1L),(Ptr)((long)DestString+OldDestLength+1L),SizeFromSource);
}
/* ======================================================= */
/* Routine: PStrCmp */
/* Purpose: Compare Pascal strings for exact match, case sensitive */
Boolean PStrCmp(StringPtr Source1String,StringPtr Source2String)/* Compare Pascal strings */
{
short theLength,Index;
Boolean theSame;
theSame = false; /* Init to different */
theLength = *Source1String++; /* Get length of one string */
if (theLength == *Source2String++) /* Compare to length of other string, easy and quick check */
{
theSame = true; /* Init to same, now we will check each character */
for (Index=1; Index <= theLength; Index++) /* Compare to length of other string, easy and quick check */
{
if (*Source1String++ != *Source2String++) /* See if this character is the same */
theSame = false; /* Different */
}
}
return(theSame);
}
/* ======================================================= */
/* Routine: GetUserEvent */
/* Purpose: See if any user events are available */
void GetUserEvent(UserEventPRec TheUserEvent)
{
UserEventHRec NextUserEvent; /* The next user event */
TheUserEvent->ID = UserEvent_None; /* Set ID to no events are available */
if (UserEventList != NIL) /* Get first entry in the list */
{
HLock((Handle)UserEventList); /* Lock for safety */
TheUserEvent->ID = (*UserEventList)->ID; /* The event ID */
TheUserEvent->ID2 = (*UserEventList)->ID2; /* The optional ID */
TheUserEvent->Data1 = (*UserEventList)->Data1; /* The optional data */
TheUserEvent->Data2 = (*UserEventList)->Data2; /* The optional data */
TheUserEvent->theHandle = (*UserEventList)->theHandle;/* The optional handle */
NextUserEvent = (*UserEventList)->Next; /* The next list */
DisposHandle((Handle)UserEventList); /* Remove this list item */
UserEventList = NextUserEvent; /* Make the next item the new first item */
}
}
/* ======================================================= */
/* Routine: Add_UserEvent */
/* Purpose: Add a user event */
void Add_UserEvent(short ID1,short ID2,long Data1,long Data2,Handle theHandle)
{
UserEventHRec NewUserEvent; /* The new user event */
UserEventHRec theUserEvent; /* The user event */
NewUserEvent = (UserEventHRec)NewHandle(sizeof(UserEventRec));/* Allocate a record */
if (NewUserEvent != NIL) /* Only do if we got the new record */
{
HLock((Handle)NewUserEvent); /* Lock for safety */
(*NewUserEvent)->ID = ID1; /* The event ID */
(*NewUserEvent)->ID2 = ID2; /* The optional ID */
(*NewUserEvent)->Data1 = Data1; /* The optional data */
(*NewUserEvent)->Data2 = Data2; /* The optional data */
(*NewUserEvent)->theHandle = theHandle; /* The optional handle */
(*NewUserEvent)->Next = NIL; /* No next item after this one */
if (UserEventList == NIL) /* See if anyone is in the list yet */
UserEventList = NewUserEvent; /* Make this one the first in the list */
else
{
theUserEvent = UserEventList; /* Get the first one */
while ((*theUserEvent)->Next != NIL) /* Get the next one */
{
theUserEvent = (*theUserEvent)->Next;
}
(*theUserEvent)->Next = NewUserEvent; /* Tack on to the end */
}
}
}
/* ======================================================= */
/* Routine: SetNameForPopup */
/* Purpose: Set the title for a popup control */
void SetNameForPopup(ControlHandle theControl)
{
Handle theHandle; /* The resource handle */
ResType theType; /* Returned type */
short theID; /* Returned ID */
short theMenuID; /* Menu ID */
theMenuID = GetCtlMax(theControl); /* Get the menu ID */
theHandle = Get1Resource('MENU', theMenuID); /* See if the resource is out there */
if (theHandle != nil) /* See if we got the menu */
GetResInfo(theHandle,&theID,&theType,sTemp); /* Get the title */
else /* Else no menu here */
sTemp[0] = 0; /* Get the title */
SetCTitle(theControl,sTemp); /* Set the title */
}
/* ======================================================= */
/* Routine: Make_A_List */
/* Purpose: This is a routine used to make a new list */
void Make_A_List(ListHandle *theList,Rect *theListRect,WindowPtr theWindow,short theStringResourceID,
short theSize,short theFont,Style theStyle,Boolean InDialog)
{
Point cSize; /* Use to point to proper row */
Handle theHandle; /* Temp Handle */
Rect dataBounds;
TextSize(theSize); /* Set text size */
TextFont(theFont); /* Set text font */
TextFace(theStyle); /* Set text style */
tempRect = *theListRect;
tempRect.right = tempRect.right - 15; /* Go inside the scroll bar area */
SetRect(&dataBounds, 0, 0, 1, 0); /* Make the empty list */
cSize.h = theListRect->right - 15 - theListRect->left;/* Get the width of the list */
cSize.v = 0; /* Set the HEIGHT of each list element, based on font selected */
*theList = LNew(&tempRect, &dataBounds, cSize, 0, theWindow, TRUE, FALSE, FALSE, TRUE);/* Create the list */
(**theList)->selFlags = lOnlyOne + lNoNilHilite; /* Set for only one active item at a time */
LDoDraw(FALSE,*theList); /* Do not Draw this list structure */
theHandle = Get1Resource('STR#',theStringResourceID);/* See if any strings */
if (theHandle != NIL)
{
cSize.h = 0; /* Point to the correct column, starts at zero */
cSize.v = -1; /* Point to the correct row, starts at zero */
do
{
GetIndString(sTemp, theStringResourceID, cSize.v + 2);/* Get the new string */
if (sTemp[0] > 0)
Add_List_String(sTemp, *theList, &cSize);/* Add in the new string */
}
while (sTemp[0] != 0); /* Add all the strings in this resource */
}
LDoDraw(TRUE,*theList); /* Draw this list structure */
cSize.h = 0; /* All elements are in column 0e */
cSize.v = 0; /* Select the first list element */
LSetSelect(TRUE, cSize,*theList);
if (InDialog)
TextFont(systemFont); /* Back to the system font */
else
TextFont(applFont); /* Back to the application font */
TextSize(12); /* Back to the application size */
TextFace(0); /* Set text style */
}
/* ======================================================= */
void Play_The_Sound(short ResID)
{
Handle ResHandle; /* The sound resource handle */
short SndResourceID; /* Sound resource ID */
Str255 SndName; /* Sound name*/
ResType theType; /* Resource type */
OSErr MyErr; /* Error flag */
ResHandle = Get1Resource('snd ', ResID); /* See if the resource is out there */
if (ResHandle != NIL) /* Only do if we got the sound */
{
GetResInfo(ResHandle,&SndResourceID,&theType,SndName);
#if defined(THINK_C) || defined(THINK_CPLUS) || defined(__SC__)
MyErr = SndPlay(NIL,ResHandle,FALSE);
#else
MyErr = SndPlay(NIL,(SndListHandle)ResHandle,FALSE);
#endif
ReleaseResource(ResHandle);
}
}
/* ======================================================= */
/* Routine: Add_List_String */
/* Purpose: This is a routine used to add strings to an existing list */
void Add_List_String(Str255 theString,ListHandle theList,Point *cSize)
{
short theRow; /* The Row that we are adding */
if (theList != NIL)
{
cSize->h = 0; /* Point to the correct column */
theRow = LAddRow(1, 32000, theList); /* Add another row at the end of the list */
cSize->v = theRow; /* Point to the row just added */
LSetCell(&theString[1], theString[0], *cSize,theList);/* Place string in row just created */
}
}
/* ======================================================= */
/* Routine: Get_TE_String */
/* Purpose: This is a routine used to get a string from a TE area, limited to 250 characters */
void Get_TE_String(TEHandle theTEArea,Str255 *theString)
{
short Index; /* Use to loop thru the characters */
short TitleLength; /* Number of characters to do */
CharsHandle theCharsHandle; /* Used to get global edit text */
Ptr theStringPtr; /* Pointer to the string, byte level */
Ptr theTECharPtr; /* Pointer to the string, byte level */
theCharsHandle = TEGetText(theTEArea); /* Get the character handle */
HLock ( ( Handle ) theCharsHandle ); /* Lock it for safety */
theTECharPtr = (Ptr)*theCharsHandle; /* Get string Ptr */
TitleLength = (*theTEArea)->teLength; /* Get the number of characters */
*theString[0] = 0; /* Start with an empty string */
if (TitleLength > 0)
{
theStringPtr = (Ptr)((long)theString + (long)1);/* Start of the string data */
if (TitleLength > 250)
TitleLength = 250;
for (Index = 0; Index < TitleLength; Index++)
*theStringPtr++ = (char)(*theTECharPtr++);
*theString[0] = TitleLength;
}
}
/* ======================================================= */
/* Routine: Make_TE_Area */
/* Purpose: This is a routine used to create a TE area */
void Make_TE_Area(TEHandle *theTEArea,Rect *Position,short theFontSize,
short theFont,short DefaultStringID)
{
FontInfo ThisFontInfo; /* Use to get the font data */
TextSize(theFontSize); /* Set the size */
TextFont(theFont); /* Set the font */
GetFontInfo(&ThisFontInfo); /* Get Ascent height for positioning */
tempRect = *Position; /* Get the rect */
FrameRect(&tempRect); /* Frame this TE area */
InsetRect(&tempRect, 3, 3); /* Indent for TE inside of box */
*theTEArea = TENew(&tempRect, &tempRect); /* Create the TE area */
if (theInput != NIL) /* See if there is already a TE area */
TEDeactivate(theInput); /* Yes, so turn it off */
theInput = *theTEArea; /* Activate the TE area */
GetIndString(sTemp, DefaultStringID, 1); /* Get the default string */
TESetText(&sTemp[1], sTemp[0], theInput); /* Place default text in the TE area */
TEActivate(theInput); /* Make the TE area active */
TextSize(12); /* Restore the size */
TextFont(applFont); /* Restore the font */
}
/* ======================================================= */
/* Routine: Plot_Sicn */
/* Purpose: This is a routine used to plot an Sicn, small 16x16 icon */
void Plot_Sicn(short theSicnID,Rect *Position)
{
typedef struct SmallIconRec{
long theIcon[16];
}SmallIconRec,*SmallIconPtr,**SmallIconHand;
SmallIconHand SmallIcon; /* Handle to the SICN resource */
BitMap theBitMap; /* Bitmap for plotting */
Rect sourceRect, DestRect; /* Rects for plotting */
GrafPtr thePort; /* Port to draw on to */
SmallIcon = (SmallIconHand)GetResource('SICN', theSicnID);/* Get the resource */
if (SmallIcon != NIL) /* Do if there is a resource */
{
SetRect(&sourceRect, 0, 0, 16, 16); /* Sicns are 16 x 16 */
DestRect = *Position; /* Destination */
theBitMap.baseAddr = (Ptr)&(*SmallIcon)->theIcon;/* Base address of the bitmap */
theBitMap.rowBytes = 2; /* 2*8 = 16 */
theBitMap.bounds = sourceRect; /* Source rect size */
GetPort(&thePort); /* Get the current port */
CopyBits(&theBitMap, &thePort->portBits, &sourceRect, &DestRect, srcCopy, NIL);/* Plot it */
}
}
/* ======================================================= */
/* Routine: HandleWScrollBar */
/* Purpose: This is a routine used to handle a scrollbar */
void HandleWScrollBar (Point myPt,short code,short Increment,short LIncrement,ControlHandle theControl)
{
short theValue; /* Value of the scrollbar */
long MaxTick; /* Timer used for repeat scrolling */
Boolean FirstTime; /* Flag to start scrolling */
short Start,Stop;
Start = GetCtlMin(theControl);
Stop = GetCtlMax(theControl);
FirstTime = TRUE; /* Do the scroll the first time also */
while (StillDown() || FirstTime) /* Do the scroll as long as the button is down */
{ /* Timer used for repeat scrolling */
FirstTime = FALSE; /* Do the scroll the first time only unless auto */
HiliteControl(theControl, code); /* Darken the arrow */
theValue = GetCtlValue(theControl); /* Get current state */
if (code == inUpButton) /* See if in the up/left arrow */
{
theValue = theValue - Increment; /* Subtract the single decrement */
if (theValue < Start) /* Check for boundary conditions */
theValue = Start; /* Bump at the start value */
}
if (code == inDownButton) /* See if in the down/right arrow */
{
theValue = theValue + Increment; /* Add the single increment */
if (theValue > Stop) /* Check for boundary conditions */
theValue = Stop; /* Bump at the stop value */
}
if (code == inPageUp) /* See if in the up/left grey area */
{
theValue = theValue - LIncrement; /* Subtract the page increment */
if (theValue < Start) /* Check for boundary conditions */
theValue = Start; /* Bump at the Start value */
}
if (code == inPageDown) /* See if in the down/right grey area */
{
theValue = theValue + LIncrement; /* Add the page increment */
if (theValue > Stop) /* Check for boundary conditions */
theValue = Stop; /* Bump at the Stop value */
}
if (code == inThumb) /* See if in the drag box area */
{
code = TrackControl(theControl, myPt, NIL); /* Let the OS drag it around */
theValue = GetCtlValue(theControl); /* Get current state */
}
SetCtlValue(theControl, theValue); /* Set new state */
MaxTick = TickCount() + 9; /* Time delay for auto-scroll */
do /* Start of delay routine */
{}
while ((Button()) && (TickCount() < MaxTick)); /* Exit when time up or mouse button up */
HiliteControl(theControl, 0); /* Lighten the arrow */
} /* End for StillDown */
}
/* ======================================================= */
/* Routine: mySelectDlgFilter */
/* Purpose: Filter routine for Select Volume routine */
static pascal short mySelectDlgFilter (short item,DialogPtr theDialog,Ptr myDataPtr)
{
short theItem;
short theWidth;
short theNameWidth;
short DType;
Handle DItem;
ControlHandle CItem;
Str255 sTemp;
Str255 theName;
Str255 LastChar;
Point cSize;
Rect dataBounds;
Boolean NamesAreSame;
theItem = item;
if (theItem == sfHookNullEvent)
{
NamesAreSame = PStrCmp((StringPtr)&Last_Name,(StringPtr)&Files.theStdFileReply.sfFile.name);
if ((Last_vRefNum != Files.theStdFileReply.sfFile.vRefNum) || (Last_parID != Files.theStdFileReply.sfFile.parID) || (!NamesAreSame))
theItem = sfItemFileListUser;
}
else
theItem = theItem;
if (theItem == sfItemFileListUser)
{
if ((Last_vRefNum != Files.theStdFileReply.sfFile.vRefNum) || (Last_parID != Files.theStdFileReply.sfFile.parID) || (Last_Name != Files.theStdFileReply.sfFile.name))
{
Last_vRefNum = Files.theStdFileReply.sfFile.vRefNum;
Last_parID = Files.theStdFileReply.sfFile.parID;
PStrCopy((Str255 *)Files.theStdFileReply.sfFile.name,&Last_Name);
GetDItem(theDialog, 10, &DType, &DItem, &tempRect);
theWidth = tempRect.right - tempRect.left - 10;
PStrCopy((Str255 *)"\pSelect '",&sTemp );
theWidth = theWidth - StringWidth(sTemp);
PStrCopy((Str255 *)Files.theStdFileReply.sfFile.name,&theName);
theNameWidth = StringWidth(theName);
if (theNameWidth > theWidth)
{
LastChar[0] = 1;
LastChar[1] = theName[theName[0]];
PStrCopy(&theName,&sTemp);
PStrCat((Str255 *)"\p...",&sTemp);
PStrCat(&LastChar,&sTemp);
while (StringWidth(sTemp) > (theWidth - 5))
{
theName[0] = theName[0] - 1;
PStrCopy(&theName,&sTemp);
PStrCat((Str255 *)"\p...",&sTemp);
PStrCat(&LastChar,&sTemp);
}
PStrCat((Str255 *)"\p...",&theName);
PStrCat(&LastChar,&theName);
}
PStrCopy((Str255 *)"\pSelect '", &sTemp );
PStrCat(&theName,&sTemp);
PStrCat((Str255 *)"\p'",&sTemp);
CItem = (ControlHandle)DItem; /* Change dialog handle to control handle */
SetCTitle(CItem, sTemp);
if (Files.theStdFileReply.sfIsFolder || Files.theStdFileReply.sfIsVolume)
HiliteControl(CItem, 0);
else
HiliteControl(CItem,255);
}
}
else if (theItem == 10)
theItem = sfItemOpenButton;
return(theItem);
}
/* ======================================================= */
/* Routine: mySelectCustomFileFilter */
/* Purpose: Filter file routine for Select Volume routine */
static pascal Boolean mySelectCustomFileFilter (CInfoPBPtr pb,Ptr myDataPtr)
{
Boolean HideTheItem;
HFileInfo *FileRecPtr;
HideTheItem = true;
FileRecPtr = (HFileInfo *)pb;
if ((FileRecPtr->ioFlAttrib & 0x0010) != 0) /* Doing Folder */
HideTheItem = false;
return(HideTheItem);
}
/* ======================================================= */
/* Routine: Do_The_Select_Volume */
/* Purpose: This is a routine used to select a user selected folder or volume */
/* Return TRUE for opened the file OK, else return FALSE */
Boolean Do_The_Select_Volume (FSSpec *theFile) /* Select a volume */
{
short Screen_Width; /* Size of the current screen */
short Screen_Height; /* Size of the current screen */
Point Where; /* Used for placing the SF dialog */
Boolean OpenedOK; /* Flag to return */
#if defined(powerc) || defined(__powerc)
FileFilterYDUPP gMyFileFilterYDUPP;
DlgHookYDUPP gMyDlgHookYDUPP;
#endif
#if defined(powerc) || defined(__powerc)
gMyFileFilterYDUPP = NewFileFilterYDProc(mySelectCustomFileFilter);
gMyDlgHookYDUPP = NewDlgHookYDProc(mySelectDlgFilter);
#endif
Screen_Width = screenRect.bounds.right - screenRect.bounds.left;/* Width of this screen */
Screen_Height = screenRect.bounds.bottom - screenRect.bounds.top;
Where.h = (Screen_Width / 2) - (304 / 2); /* Place to put this dialog */
Where.v = (Screen_Height / 4) - (104 / 2);
if (Where.v < 60)
Where.v = 60;
InitCursor();
Files.typeList[0] = 'GRC ';
Last_vRefNum = -2;
Last_parID = -2;
#if defined(powerc) || defined(__powerc)
CustomGetFile(gMyFileFilterYDUPP,0,Files.typeList,&Files.theStdFileReply,
512,Where,gMyDlgHookYDUPP, nil, nil, nil, nil);
#else
CustomGetFile((FileFilterYDProcPtr)mySelectCustomFileFilter,0,Files.typeList,&Files.theStdFileReply,
512,Where,(DlgHookYDProcPtr)mySelectDlgFilter, nil, nil, nil, nil);
#endif
OpenedOK = false; /* Init to did not open the file */
if (Files.theStdFileReply.sfGood) /* Only do if the user did not cancel */
{
*theFile = Files.theStdFileReply.sfFile; /* Save the FSSpec */
BlockMove((Ptr)&Files.theStdFileReply.sfFile.name,&Files.inputFileName,Files.theStdFileReply.sfFile.name[0]+1);
OpenedOK = true; /* We selected a folder */
}
else
Files.inputFileName[0] = 0; /* No name for a folder */
return(OpenedOK);
}
/* ======================================================= */
/* Routine: Do_The_Open_File */
/* Purpose: This is a routine used to open a user selected file */
/* Return TRUE for opened the file OK, else return FALSE */
Boolean Do_The_Open_File (short NumberOfTypes,short *theVolRefNum,ProcPtr fileFilter,
ProcPtr dlgHook)
{
short Screen_Width; /* Size of the current screen */
short Screen_Height; /* Size of the current screen */
Point Where; /* Used for placing the SF dialog */
Boolean OpenedOK; /* Flag to return */
OSErr ErrorCode;
#if defined(powerc) || defined(__powerc)
FileFilterUPP gMyFileFilterUPP;
DlgHookUPP gMyDlgHookUPP;
#endif
#if defined(powerc) || defined(__powerc)
gMyFileFilterUPP = NewFileFilterProc(fileFilter);
gMyDlgHookUPP = NewDlgHookProc(dlgHook);
#endif
Screen_Width = screenRect.bounds.right - screenRect.bounds.left;/* Width of this screen */
Screen_Height = screenRect.bounds.bottom - screenRect.bounds.top;
Where.h = (Screen_Width / 2) - (304 / 2); /* Place to put this dialog */
Where.v = (Screen_Height / 4) - (104 / 2);
if (Where.v < 60)
Where.v = 60;
InitCursor();
#if defined(powerc) || defined(__powerc)
SFGetFile(Where,(StringPtr)"/pNot used",gMyFileFilterUPP,NumberOfTypes,Files.typeList,gMyDlgHookUPP,&Files.Reply);
#else
SFGetFile(Where,(StringPtr)"/pNot used",(FileFilterProcPtr)fileFilter,NumberOfTypes,
Files.typeList,(DlgHookProcPtr)dlgHook,&Files.Reply);
#endif
*theVolRefNum = 0;
Files.inputRefNum = 0; /* We did not open */
OpenedOK = false; /* Init to did not open the file */
if (Files.Reply.good) /* Only do if the user did not cancel */
{
BlockMove((Ptr)&Files.Reply.fName,&Files.inputFileName,Files.Reply.fName[0]+1);
ErrorCode = SetVol(nil, Files.Reply.vRefNum); /* Set to this volume for later opens */
*theVolRefNum = Files.Reply.vRefNum;
OpenedOK = true; /* Flag that we are open OK */
}
else
Files.inputFileName[0] = 0; /* No name for a file */
return(OpenedOK);
}
/* ======================================================= */
/* Routine: Do_The_Save_File */
/* Purpose: This is a routine used to save a user selected file */
/* Return TRUE for opened the file OK, else return FALSE */
Boolean Do_The_Save_File (OSType creator,OSType fileType,Str255 *Prompt,Str255 *DefaultName,
short *theVolRefNum,short *theRefNum,ProcPtr dlgHook)
{
short Screen_Width; /* Size of the current screen */
short Screen_Height; /* Size of the current screen */
Point Where; /* Used for placing the SF dialog */
Boolean OpenedOK; /* Flag to return */
OSErr ErrorCode;
#if defined(powerc) || defined(__powerc)
DlgHookUPP gMyDlgHookUPP;
#endif
#if defined(powerc) || defined(__powerc)
gMyDlgHookUPP = NewDlgHookProc(dlgHook);
#endif
Screen_Width = screenRect.bounds.right - screenRect.bounds.left;/* Width of this screen */
Screen_Height = screenRect.bounds.bottom - screenRect.bounds.top;
Where.h = (Screen_Width / 2) - (304 / 2); /* Place to put this dialog */
Where.v = (Screen_Height / 4) - (104 / 2);
if (Where.v < 60)
Where.v = 60;
InitCursor();
#if defined(powerc) || defined(__powerc)
SFPutFile(Where,(StringPtr)Prompt,(StringPtr)DefaultName,gMyDlgHookUPP,&Files.Reply);
#else
SFPutFile(Where,(StringPtr)Prompt,(StringPtr)DefaultName,(DlgHookProcPtr)dlgHook,&Files.Reply);
#endif
BlockMove((Ptr)&Files.Reply.fName,&Files.outputFileName,Files.Reply.fName[0]+1);
*theVolRefNum = Files.Reply.vRefNum;
*theRefNum = 0;
Files.outputRefNum = 0;
OpenedOK = false; /* Init to did not open the file */
if (Files.Reply.good) /* Only do if the user did not cancel */
{
ErrorCode = FSDelete((StringPtr)&Files.Reply.fName, Files.Reply.vRefNum);/* Delete an older file */
ErrorCode = Create((StringPtr)&Files.Reply.fName, Files.Reply.vRefNum, creator, fileType);/* Create the file */
ErrorCode = FSOpen((StringPtr)&Files.Reply.fName, Files.Reply.vRefNum, &Files.outputRefNum);/* Try to open the file */
if (ErrorCode == 0) /* See if we opened it cleanly */
{
ErrorCode = SetFPos(Files.outputRefNum, fsFromStart, 0);/* Start at file beginning */
ErrorCode = SetVol(nil, *theVolRefNum); /* Set for later saves */
*theRefNum = Files.outputRefNum;
*theVolRefNum = Files.Reply.vRefNum;
OpenedOK = true; /* We opened the file OK */
}
else
{
ErrorCode = FSClose(Files.outputRefNum); /* Close it if we can, safety */
SysBeep(20); /* Just beep at the user, caller can do more */
Files.outputRefNum = 0; /* Make sure the refnum is inited */
}
}
return(OpenedOK);
}
/* ======================================================= */
/* Routine: PageSetup */
/* Purpose: Do the page setup */
void PageSetup(void)
{
Boolean Result; /* Result from Setup dialog */
PrOpen(); /* Open the printer driver */
if (PrError() == noErr) /* Only do if no error */
{
if (Printing.hPrint == NIL) /* Make a print record if there is none */
{
Printing.hPrint = (THPrint)NewHandle(sizeof(TPrint));
HLock((Handle)Printing.hPrint);
PrintDefault(Printing.hPrint); /* Init to default values */
}
Result = PrStlDialog(Printing.hPrint); /* Setup dialog */
PrClose();
}
else
SysBeep(1);
}
/* ======================================================= */
/* Routine: PrintJobSetup */
/* Purpose: Do the job setup */
void PrintJobSetup(void)
{
Boolean Result; /* Result from Setup dialog */
PrOpen(); /* Open the printer driver */
if (PrError() == noErr) /* Only do if no error */
{
if (Printing.hPrint == NIL) /* Make a print record if there is none */
{
Printing.hPrint = (THPrint)NewHandle(sizeof(TPrint));
HLock((Handle)Printing.hPrint);
PrintDefault(Printing.hPrint); /* Init to default values */
}
Result = PrJobDialog(Printing.hPrint); /* Setup dialog */
PrClose();
}
else
SysBeep(1);
}
/* ======================================================= */
/* Routine: OpenThePrinter */
/* Purpose: Open the printer and driver for use */
void OpenThePrinter(Boolean *Cancelled)
{
PrOpen(); /* Open the printer driver */
if (PrError() == noErr) /* Only do if no error */
{
Printing.PrinterIsOpen = FALSE; /* Whether printer is open or not */
if (Printing.hPrint == NIL) /* Make a print record if there is none */
{
Printing.hPrint = (THPrint)NewHandle(sizeof(TPrint));
HLock((Handle)Printing.hPrint);
PrintDefault(Printing.hPrint); /* Init to default values */
}
*Cancelled = PrJobDialog(Printing.hPrint); /* Setup dialog */
Printing.CopyCount = (*Printing.hPrint)->prJob.iCopies; /* Get number of copies to do */
*Cancelled = !(*Cancelled); /* Inverted logic */
Printing.pPrPort = nil;
if (*Cancelled == false) /* Do if they did not cancel */
{
Printing.PrinterIsOpen = true; /* Whether printer is open or not */
Printing.PageCount = 1; /* For adding in page number */
Printing.LineCount = 1; /* For printing */
Printing.pPrPort = PrOpenDoc(Printing.hPrint, nil, nil);/* Get printing port */
}
}
else
{
SysBeep(1);
*Cancelled = TRUE;
}
}
/* ======================================================= */
/* Routine: CloseThePrinter */
/* Purpose: Close the printer */
void CloseThePrinter(void)
{
if (Printing.pPrPort != nil) /* Do if we have a port */
{
PrCloseDoc(Printing.pPrPort); /* Clear printing port */
Printing.pPrPort = nil;
}
if (Printing.hPrint != nil) /* Do if we have a record */
{
if (((*Printing.hPrint)->prJob.bJDocLoop == bSpoolLoop) && (PrError() == noErr))
PrPicFile(Printing.hPrint, NIL, NIL, NIL, &Printing.prStatus);/* Spool it */
}
}
/* ======================================================= */
/* Routine: SetupTheItem */
/* Purpose: Setup a dialog or alert item */
void SetupTheItem(DialogPtr theDialog,short ItemID,Boolean SizeIt,Boolean ShowIt,
Boolean EnableIt,Boolean SetTheMax,Rect *thePosition,long ExtraData,short StringID)
{
Rect tempRect; /* Temporary rectangle */
short DType; /* Type of dialog item */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem; /* Control handle */
GetDItem(theDialog,ItemID,&DType,&DItem,&tempRect);/* Get the item handle and size */
CItem = (ControlHandle)DItem; /* Change to control handle */
if (SizeIt) /* Have to resize all CDEF connected controls */
SizeControl(CItem, tempRect.right-tempRect.left, tempRect.bottom-tempRect.top);/* Size it */
*thePosition = tempRect; /* Pass back the zone location and size */
if (ExtraData != NIL) /* See if extra data for a CDEF */
(*CItem)->contrlData = (Handle)ExtraData; /* Send it */
if (StringID != 0) /* See if a CDEF and needs the title set again*/
{
GetIndString(sTemp,StringID,1); /* Get the string */
SetCTitle(CItem,sTemp); /* Set the string */
}
if (EnableIt) /* See if enable or disable the zone */
HiliteControl (CItem,0); /* Enable the zone */
else
HiliteControl (CItem,255); /* Dim the zone */
if (SetTheMax)
SetCtlMax(CItem,12345); /* Set the flag to the CDEF */
if (ShowIt)
ShowControl(CItem); /* Show it to activate it */
}
/* ======================================================= */
/* Routine: CenterOnColorScreen */
/* Purpose: Center a window onto the deepest color screen */
void CenterOnColorScreen (WindowPtr theWindow )
{
Rect tempRect,gdRect,temp2Rect; /* Temporary rectangle */
GDHandle theDevice; /* Graphic device */
if ((theWindow != NIL) && (Has.ColorQD)) /* Make sure it is safe to go ahead */
{
SetRect(&tempRect,-32000,-32000,32000,32000); /* Look in all directions */
theDevice = GetMaxDevice(&tempRect); /* Get the deepest device */
if (theDevice != NIL) /* Make sure we got a device */
{
gdRect = (*theDevice)->gdRect; /* Get the device rect */
temp2Rect = theWindow->portRect; /* Get the window rect */
tempRect.top = gdRect.top + ((gdRect.bottom-gdRect.top)/2) - ((temp2Rect.bottom-temp2Rect.top)/2);
tempRect.left = gdRect.left + ((gdRect.right-gdRect.left)/2) - ((temp2Rect.right-temp2Rect.left)/2);
MoveWindow(theWindow, tempRect.left, tempRect.top, TRUE);/* Move the window*/
SetPort(theWindow); /* Prepare to write into our window */
}
}
}
/* ======================================================= */
/* Routine: GetDeepestColorScreenRect */
/* Purpose: Get the deepest color screen rect */
void GetDeepestColorScreenRect (Rect *DeepRect )
{
Rect tempRect; /* Temporary rectangle */
GDHandle theDevice; /* Graphic device */
*DeepRect = screenRect.bounds; /* Default to the main screen */
theDevice = NIL; /* Default to no device */
if (Has.ColorQD) /* See if color QuickDraw is around */
{
SetRect(&tempRect,-32000,-32000,32000,32000); /* Look in all directions */
theDevice = GetMaxDevice(&tempRect); /* Get the deepest device */
if (theDevice != NIL) /* Make sure we got a device */
*DeepRect = (*theDevice)->gdRect; /* Get the device rect */
}
}
/* ======================================================= */
void HiliteDefaultButton(DialogPtr theDialog,short theItem)
{
Rect tempRect;
short DType; /* Type of dialog item */
Handle DItem; /* Handle to the dialog item */
GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
PenSize(3, 3); /* Change pen to draw thick default outline */
InsetRect(&tempRect, -4, -4); /* Draw outside the button by 1 pixel */
FrameRoundRect(&tempRect,16,16); /* Draw the outline */
PenSize(1, 1); /* Restore the pen size to the default value */
}
/* ======================================================= */
void CheckKeysInDialog(DialogPtr theDialog,Boolean *valMyFilter,EventRecord *theEvent,short *itemHit)
{
short chCode; /* Key entered */
char MyCmdKey; /* The command key */
Boolean CmdDown; /* Flag for command key used */
Rect tempRect; /* Temporary rectangle */
short DType; /* Type of dialog item */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem; /* Control handle */
long LTemp;
if (theEvent->what == keyDown)
{
chCode = (short)theEvent->message & charCodeMask;/* Get character */
MyCmdKey = (char)chCode; /* Change to ASCII */
CmdDown = ((theEvent->modifiers & cmdKey) != 0);/* Get command key state */
if (CmdDown) /* Do if command key was down */
{
if ((MyCmdKey == 'x') || (MyCmdKey == 'X'))
{
DlgCut(theDialog);
*valMyFilter = TRUE;
}
else if ((MyCmdKey =='c') || (MyCmdKey == 'C'))
{
DlgCopy(theDialog);
*valMyFilter = TRUE;
}
else if ((MyCmdKey =='v') || (MyCmdKey == 'V'))
{
DlgPaste(theDialog);
*valMyFilter = TRUE;
}
}
else if ((chCode == 13) || (chCode == 3)) /* CR or Enter */
{
*valMyFilter = TRUE; /* Flag we got a hit */
*itemHit = 1; /* Default for CR */
GetDItem (theDialog ,*itemHit, &DType, &DItem, &tempRect);/* Get the item */
if (DType == (ctrlItem + btnCtrl)) /* If a button then ... */
{
CItem = (ControlHandle)DItem; /* Make it a controlhandle */
HiliteControl(CItem, 10); /* Hilite it */
LTemp = TickCount() + 15; /* Flash the button for 1/4 second */
do
{}
while (LTemp > TickCount());
HiliteControl(CItem, 0); /* UnHilite it */
}
}
}
}
/* ======================================================= */
void SetupNormalControl(DialogPtr theDialog,short theItem,Boolean Enabled,short InitialValue)
{
Rect tempRect; /* Temporary rectangle variable */
short DType; /* Type of dialog item */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem; /* Control handle */
GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
CItem = (ControlHandle)DItem; /* Change dialog handle to control handle */
if (Enabled) /* See if enable or disable the zone */
HiliteControl (CItem,0); /* Enable the zone */
else
HiliteControl (CItem,255); /* Dim the zone */
SetCtlValue(CItem,InitialValue);
}
/* ======================================================= */
static void BasicSetup(DialogPtr theDialog,short theItem,Boolean Enabled,short MessageResID,
ControlHandle *theCItem)
{
Rect tempRect; /* Temporary rectangle variable */
short DType; /* Type of dialog item */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem; /* Control handle */
Str255 sTemp;
GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
CItem = (ControlHandle)DItem; /* Change dialog handle to control handle */
SizeControl(CItem, tempRect.right-tempRect.left, tempRect.bottom-tempRect.top);/* Size it */
if (Enabled) /* See if enable or disable the zone */
HiliteControl (CItem,0); /* Enable the zone */
else
HiliteControl (CItem,255); /* Dim the zone */
SetCtlValue(CItem,0);
if (MessageResID != 0)
{
GetIndString(sTemp,MessageResID,1); /* Get the string */
SetCTitle(CItem,sTemp); /* Set the string */
}
*theCItem = CItem;
}
/* ======================================================= */
void SetupHotSpot(DialogPtr theDialog,short theItem,Boolean MakeHotSpot,long LineWidth,
long ShadowWidth,short MessageResID,Boolean Enabled)
{
ControlHandle CItem; /* Control handle */
long LTemp;
BasicSetup(theDialog,theItem,Enabled,MessageResID,&CItem);
if (MakeHotSpot)
LTemp = 0x00FF0000; /* Tell the CDEF that it is a HotSpot */
else
LTemp = 0x00000000; /* Tell the CDEF that it is a Rectangle */
if (MessageResID != 0)
LTemp = LTemp + 0x01000000;
LTemp = LTemp + ((0x000000FF & LineWidth) * 0x00000100); /* Set the line width */
LTemp = LTemp + (0x000000FF & ShadowWidth); /* Set the shadow width */
(*CItem)->contrlData = (Handle)LTemp; /* Send it */
ShowControl(CItem); /* Show it to activate it */
}
/* ======================================================= */
void SetupPlugin(DialogPtr theDialog,short theItem,Boolean Enabled,long NormalID,long HilitedID,
short MessageResID)
{
ControlHandle CItem; /* Control handle */
long LTemp;
BasicSetup(theDialog,theItem,Enabled,MessageResID,&CItem);
LTemp = (HilitedID * 0x00010000) + NormalID;
(*CItem)->contrlData = (Handle)LTemp; /* Send it */
SetCtlMax(CItem,12345); /* Set the flag to the CDEF */
ShowControl(CItem); /* Show it to activate it */
}
/* ======================================================= */
void SetupMinMaxValue(DialogPtr theDialog,short theItem,short min,short max,short value)
{
Rect tempRect; /* Temporary rectangle variable */
short DType; /* Type of dialog item */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem; /* Control handle */
GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
CItem = (ControlHandle)DItem; /* Change dialog handle to control handle */
SetCtlMin(CItem,min); /* The Min */
SetCtlMax(CItem,max); /* The Max */
SetCtlValue(CItem,value); /* The first selection */
}
/* ======================================================= */
void SetupPopupMenu(DialogPtr theDialog,short theItem,Boolean Enabled,short theMenuID,short value)
{
Rect tempRect; /* Temporary rectangle variable */
short DType; /* Type of dialog item */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem; /* Control handle */
GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
CItem = (ControlHandle)DItem; /* Change dialog handle to control handle */
SizeControl(CItem,tempRect.right - tempRect.left, tempRect.bottom - tempRect.top);/* Size it to the item size */
SetCtlValue(CItem,value); /* The first selection */
SetCtlMax(CItem,theMenuID); /* The max value is the menu ID */
if (Enabled) /* See if enable or disable the zone */
HiliteControl (CItem,0); /* Enable the zone */
else
HiliteControl (CItem,255); /* Dim the zone */
SetNameForPopup(CItem); /* Set the popup title */
ShowControl(CItem); /* Show it to activate it */
}
/* ======================================================= */
void SetupPalette(DialogPtr theDialog,short theItem,Boolean Enabled,long NumberRows,long NumberCols,
long PalPictureID,long HiliteMethod)
{
ControlHandle CItem; /* Control handle */
BasicSetup(theDialog,theItem,Enabled,0,&CItem);
SetCtlMax(CItem,(NumberRows * 0x00000100) + NumberCols); /* The max value is the (rows * 0x0100) + columns */
SetCtlValue(CItem,(1 * 0x0100) + 1 ); /* The current value is the (rows * 0x0100) + columns */
(*CItem)->contrlData = (Handle)((0xFF000000 | PalPictureID) + (HiliteMethod * 0x00010000));/* Picture ID and hilite method */
ShowControl(CItem); /* Show it to activate it */
}
/* ======================================================= */
void SetupIconSicn(DialogPtr theDialog,short theItem,Boolean Enabled,
long NormalID,long HilitedID)
{
ControlHandle CItem; /* Control handle */
long LTemp;
BasicSetup(theDialog,theItem,Enabled,0,&CItem);
LTemp = (NormalID * 0x00010000) + HilitedID;
(*CItem)->contrlData = (Handle)LTemp; /* Send it */
SetCtlMax(CItem,12345); /* Set the flag to the CDEF */
ShowControl(CItem); /* Show it to activate it */
}
/* ======================================================= */
void ClearTheRadio(DialogPtr theDialog,short theItem,short *value)
{
Rect tempRect; /* Temporary rectangle variable */
short DType; /* Type of dialog item */
Handle DItem; /* Handle to the dialog item */
ControlHandle CItem; /* Control handle */
GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get which item was pressed */
CItem = (ControlHandle)DItem; /* Change the pointer for getting to the control */
SetCtlValue(CItem,0);
*value = 0; /* Set the current Radio value */
}
/* ======================================================= */
void DrawStaticTextBox(short ResID,Rect *theRect,short Justify,short theSize,
short theFont,Style theStyle)
{
Str255 sTemp;
TextSize(theSize); /* Set text size */
TextFont(theFont); /* Set text font */
TextFace(theStyle); /* Set text style */
GetIndString(sTemp,ResID,1); /* Get the string */
TextBox(&sTemp[1],sTemp[0],theRect,Justify);
TextFont(applFont); /* Back to the application font */
TextSize(12); /* Back to the application size */
TextFace(0); /* Set text style */
}
/* ======================================================= */
void DrawStaticLine(short ResID,short Left,short Top,short theSize,short theFont,Style theStyle)
{
Str255 sTemp;
TextSize(theSize); /* Set text size */
TextFont(theFont); /* Set text font */
TextFace(theStyle); /* Set text style */
GetIndString(sTemp,ResID,1); /* Get the string */
MoveTo(Left,Top + theSize - 3);
DrawString(sTemp);
TextFont(applFont); /* Back to the application font */
TextSize(12); /* Back to the application size */
TextFace(0); /* Set text style */
}
/* ======================================================= */
void DrawTheTEArea(Rect *theTERect,TEHandle theTE,short theSize,short theFont,Style theStyle)
{
TextSize(theSize); /* Set text size */
TextFont(theFont); /* Set text font */
TextFace(theStyle); /* Set text style */
FrameRect(theTERect); /* Frame this TE area */
if (theTE != nil)
TEUpdate(theTERect,theTE); /* Update the TE area */
TextFont(applFont); /* Back to the application font */
TextSize(12); /* Back to the application size */
TextFace(0); /* Set text style */
}
/* ======================================================= */
ControlHandle MakeNormalControl(WindowPtr theWindow,short theResID,Boolean Enabled,short InitialValue)
{
ControlHandle theCtrl;
theCtrl = GetNewControl(theResID,theWindow); /* Make a new control */
SetCtlValue(theCtrl,InitialValue); /* Set the value */
if (Enabled)
HiliteControl(theCtrl,0); /* Enable the control */
else
HiliteControl(theCtrl,255); /* Disable the control */
return(theCtrl);
}
/* ======================================================= */
ControlHandle MakeHotSpot(WindowPtr theWindow,short theResID,Boolean MakeHotSpot,long LineWidth,
long ShadowWidth,short MessageResID,Boolean Enabled)
{
ControlHandle theCtrl;
long LTemp;
Str255 sTemp;
theCtrl = GetNewControl(theResID,theWindow); /* Make a new control */
HideControl(theCtrl); /* Hide till we set all the parameters */
if (Enabled)
HiliteControl(theCtrl,0); /* Enable the control */
else
HiliteControl(theCtrl,255); /* Disable the control */
if (MakeHotSpot)
LTemp = 0x00FF0000; /* Tell the CDEF that it is a HotSpot */
else
LTemp = 0x00000000; /* Tell the CDEF that it is a Rectangle */
LTemp = LTemp + ((0x000000FF & LineWidth) * 0x00000100); /* Set the line width */
LTemp = LTemp + (0x000000FF & ShadowWidth); /* Set the shadow width */
if (MessageResID != 0)
{
LTemp = LTemp + 0x01000000;
GetIndString(sTemp,MessageResID,1); /* Get the string */
SetCTitle(theCtrl,sTemp); /* Set the string */
}
(*theCtrl)->contrlData = (Handle)LTemp; /* Send it */
SetCtlValue(theCtrl,0);
ShowControl(theCtrl); /* Show it to activate it */
return(theCtrl);
}
/* ======================================================= */
ControlHandle MakeIconSicn(WindowPtr theWindow,short theResID,Boolean Enabled,
long NormalID,long HilitedID)
{
ControlHandle theCtrl;
theCtrl = GetNewControl(theResID,theWindow); /* Make a new button */
if (Enabled)
HiliteControl(theCtrl,0); /* Enable the button */
else
HiliteControl(theCtrl,255); /* Disable the button */
(*theCtrl)->contrlData =
(Handle)((NormalID * 0x00010000) + HilitedID); /* Set the icons to be used */
return(theCtrl);
}
/* ======================================================= */
ControlHandle MakePlugin(WindowPtr theWindow,short theResID,Boolean Enabled,
long NormalID,long HilitedID,short MessageResID,short InitialValue)
{
ControlHandle theCtrl;
long LTemp;
Str255 sTemp;
theCtrl = GetNewControl(theResID,theWindow); /* Make a new button */
HideControl(theCtrl);
if (Enabled)
HiliteControl(theCtrl,0); /* Enable the button */
else
HiliteControl(theCtrl,255); /* Disable the button */
LTemp = (HilitedID * 0x00010000) + NormalID;
(*theCtrl)->contrlData = (Handle)LTemp; /* Send it */
SetCtlMax(theCtrl,12345); /* Set the flag to the CDEF */
if (MessageResID != 0)
{
GetIndString(sTemp,MessageResID,1); /* Get the string */
SetCTitle(theCtrl,sTemp); /* Set the string */
}
SetCtlValue(theCtrl,InitialValue);
ShowControl(theCtrl); /* Show it to activate it */
return(theCtrl);
}
/* ======================================================= */
void MakeMinMaxValue(ControlHandle theControl,short min,short max,short value)
{
SetCtlMin(theControl,min); /* The Min */
SetCtlMax(theControl,max); /* The Max */
SetCtlValue(theControl,value); /* The first selection */
}
/* ======================================================= */
ControlHandle MakePopupMenu(WindowPtr theWindow,short theResID,Boolean Enabled,
short theMenuID,short value)
{
ControlHandle theCtrl;
long LTemp;
Str255 sTemp;
theCtrl = GetNewControl(theResID,theWindow); /* Make a new button */
HideControl(theCtrl);
if (Enabled)
HiliteControl(theCtrl,0); /* Enable the button */
else
HiliteControl(theCtrl,255); /* Disable the button */
SetCtlMax(theCtrl,theMenuID); /* Set the menu for the CDEF */
SetCtlValue(theCtrl,value);
SetNameForPopup(theCtrl); /* Set the popup title */
ShowControl(theCtrl); /* Show it to activate it */
return(theCtrl);
}
/* ======================================================= */
void UpdateTheList(RgnHandle theRgn,ListHandle theList,Rect *theRect,short theSize,
short theFont,Style theStyle,Boolean InDialog)
{
Rect tempRect;
TextSize(theSize); /* Set text size */
TextFont(theFont); /* Set text font */
TextFace(theStyle); /* Set text style */
LUpdate(theRgn,theList); /* Update this list */
tempRect = *theRect; /* Start with full size */
InsetRect(&tempRect, -1, -1); /* Set for framing */
FrameRect(&tempRect); /* Frame it */
if (InDialog)
TextFont(systemFont); /* Back to the system font */
else
TextFont(applFont); /* Back to the application font */
TextSize(12); /* Back to the application size */
TextFace(0); /* Set text style */
}
/* ======================================================= */
void ClickInTheList(Point myPt,short modifiers,ListHandle theList,short theSize,
short theFont,Style theStyle,Boolean InDialog)
{
Boolean DoubleClick;
TextSize(theSize); /* Set text size */
TextFont(theFont); /* Set text font */
TextFace(theStyle); /* Set text style */
DoubleClick = LClick(myPt,modifiers,theList);
if (InDialog)
TextFont(systemFont); /* Back to the system font */
else
TextFont(applFont); /* Back to the application font */
TextSize(12); /* Back to the application size */
TextFace(0); /* Set text style */
}
/* ======================================================= */
ControlHandle MakePalette(WindowPtr theWindow,short theResID,Boolean Enabled,long NumberRows,
long NumberCols,long PalPictureID,long HiliteMethod)
{
ControlHandle theCtrl;
theCtrl = GetNewControl(theResID,theWindow); /* Make a new button */
HideControl(theCtrl);
if (Enabled)
HiliteControl(theCtrl,0); /* Enable the button */
else
HiliteControl(theCtrl,255); /* Disable the button */
SetCtlMax(theCtrl,(NumberRows * 0x00000100) + NumberCols); /* The max value is the (rows * 0x0100) + columns */
SetCtlValue(theCtrl,(1 * 0x0100) + 1 ); /* The current value is the (rows * 0x0100) + columns */
(*theCtrl)->contrlData = (Handle)((0xFF000000 | PalPictureID) + (HiliteMethod * 0x00010000));/* Picture ID and hilite method */
ShowControl(theCtrl); /* Show it to activate it */
return(theCtrl);
}
/* ======================================================= */
void Activate_TE_Area(Boolean InDialog,Point myPt,TEHandle theTE,short textSize,short textFont,Style textStyle)
{
TextSize(textSize); /* Set text size */
TextFont(textFont); /* Set text font */
TextFace(textStyle); /* Set text style */
if (theInput != nil) /* See if there is already a TE area */
TEDeactivate(theInput); /* ...Yes, so turn it off */
theInput = theTE;
TEActivate(theInput); /* Turn it on */
TEClick(myPt,false,theInput);
if (InDialog)
TextFont(systemFont); /* Back to the system font */
else
TextFont(applFont); /* Back to the application font */
TextSize(12);
TextFace(0);
}
/* ======================================================= */
/* ======================================================= */
$$CloseFile